/***************************************************************************
 *   Copyleft 2008-2009 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>									   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#ifndef __VSETUPCONFIG_H__
#define __VSETUPCONFIG_H__

#include "../FileIO/vXmlOutputStream.h"
#include "../FileIO/vXmlInputStream.h"
#include "./vConfigOption.h"
#include "../Renderer/vDeviceInfo.h"
#include "../../Macros/vMemoryMacros.h"

namespace Vendetta {
	/*! \class vSetupConfig
	 *   \brief A vSetupConfig class manages current configuration, loads and saves it to xml files.
	 *
	 *	vSetupConfig class inheritates from vXmlOutputStream for loading and saving to xml files.
	 *
	 *	\sa vXmlOutputStream.
	 */
	class vSetupConfig: public vXmlOutputStream, public vXmlInputStream {
	public:
		/*! \brief Default constructor.
		 *
		 */	
		vSetupConfig();

		/*! \brief Destructor.
		 *
		 */	
		virtual ~vSetupConfig();

		/*! \brief Overloaded from vXmlOutputStream.
		 *
		 */
		virtual vBool SaveToFile(const vString& fileName = "config.vcf");

		/*! \brief Overloaded from vXmlInputStream.
		*
		*/
		virtual vBool LoadFromFile(const vString& fileName = "config.vcf");

		/*! \brief Returns device info ptr for Engine3D, to init video device.
		*
		*	Before returning DeviceInfo there is made validation process.
		*	If it ends with success DeviceInfo pointer is returned otherwise 
		*	vNull is returned.
		*
		*	\return			DeviceInfo pointer.
		*/
		vDeviceInfo* DeviceInfoPtr();

		/*! \brief Returns whether device info is valid or not.
		*
		*	If it is not valid, calling DeviceInfoPtr() will return vNull.
		*
		*	\return			True if Device Info is valid, false otherwise.
		*/
		vBool IsSetupValid();

		/*! \brief Sets whether user want to save configuration in file or not.
		*
		*
		*  \param		bSave			True if config should be saved, false otherwise.
		*/
		vVoid SetToSave(vBool bSave);

	protected:
		/*! \brief Implemented from vXmlOutputStream.
		 *
		 */
		vBool preSave();

		/*! \brief Implemented from vXmlInputStream.
		*
		*/
		vBool postLoad();


	private:
		vArray<vPair<vString, vConfigOption>> mEntries;
		vDeviceInfo* mpDeviceInfo;
		vBool mSaveConfig;
	};
}


#endif // __VSETUPCONFIG_H__